# -*- coding: utf-8 -*-
"""
Created on Wed Apr  3 10:21:19 2024

@author: 刘翼
"""

import cv2
import skimage.morphology as sm
import matplotlib.pyplot as plt
# 腐蚀
img = cv2.imread(r"C:\Users\Public\opencv\Figure\car.png",0)   # 调用棋格板
#用边长为3的正方形滤波器进行腐蚀滤波
dst1 = sm.erosion(img,sm.square(3))

plt.figure('morphology',figsize=(8,8))
plt.subplot(221)
plt.title('origin image')
plt.imshow(img,plt.cm.gray)

plt.subplot(222)
plt.title('3*3 eroded image')
plt.imshow(dst1,plt.cm.gray)
#膨胀

#边长为3的正方形卷积核
dst1 = sm.dilation(img,sm.square(3)) 

plt.figure('morphology',figsize=(8,8))
plt.subplot(223)
plt.title('origin image')
plt.imshow(img,plt.cm.gray)

plt.subplot(224)
plt.title('3*3 dilation image')
plt.imshow(dst1,plt.cm.gray)

